package com.sky.controller.courier;

import com.sky.constant.MessageConstant;
import com.sky.dto.UserLoginDTO;
import com.sky.pojo.Courier;
import com.sky.result.Result;
import com.sky.service.courier.CourierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 骑手控制器层
 * @author zgp
 * @version V1.0
 * @date 2025-02-11 20:06
 */
@Slf4j
@Api(tags = "骑手相关接口")
@RestController
@RequestMapping("/courier")
public class CourierController {
    @Autowired
    private CourierService courierService;

    @ApiOperation("获取短信验证码")
    @GetMapping("/validateCodeToPhone")
    public Result<String> getSmsCode(String telephone){
        log.info("获取短信验证码：telephone = {}", telephone);
        return Result.success(courierService.getSmsCode(telephone));
    }

    @ApiOperation("骑手登录")
    @PostMapping("/login")
    public Result<Courier> login(@RequestBody UserLoginDTO userLoginDTO){
        log.info("骑手登录：userLoginDTO = {}", userLoginDTO);
        return Result.success(courierService.login(userLoginDTO));
    }

    @ApiOperation("骑手接单")
    @GetMapping("/receivingOrder")
    public Result receivingOrder(Integer courierId, Long tradeNo){
        log.info("骑手接单：courierId = {}, tradeNo = {}", courierId, tradeNo);
        courierService.receivingOrder(courierId, tradeNo);
        return Result.success(MessageConstant.GENERAL_SUCCESS);
    }

}
